import 'dart:convert';

import 'package:flutter_des/flutter_des.dart';

import '../public.dart';

class BookInfoService {
  static Future<BookInfo> get(String bookName, String bookUrl, String author,
      String reptileType) async {
    String param = await FlutterDes.encryptToHex(
        "&bookName=$bookName"
        "&bookUrl=$bookUrl"
        "&author=$author"
        "&isProxy=false"
        "&reptileType=$reptileType",
        AppConfig.cryptKey,
        iv: AppConfig.cryptIv);
    String url = AppConfig.BASE_UEL + Api.findBookInfo + param.toString();
    BookInfo bookInfo;
    Book _book;
    List<Chapter> _list;
    BaseResp res = await HttpManager().request(url, method: "post");
    Map<String, dynamic> jsonObject = jsonDecode(res.data);
    _book = Book.bookFromJson(jsonObject['book']);
    _list = Chapter.listFromJson(jsonObject['catalog']);
    bookInfo = new BookInfo(book: _book, list: _list);
    return bookInfo;
  }
}
